#include "cb.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

int main(int argc, char *argv[]) {
	int d_sock;
	
	d_sock = open_socket("en.wikipedia.org", "80");
	char buf[255];

	sprintf(buf, "GET /wiki/%s http/1.1\r\n", argv[1]);
	say(d_sock, buf);

	say(d_sock, "HOST: en.wikipedia.org\r\n\r\n");
	char rec[256];
	int bytesRcvd = recv(d_sock, rec, 255, 0);
	while (bytesRcvd) {
		if (bytesRcvd == -1) {
			error("Can't read from server");
		}

		rec[bytesRcvd] = '\0';
		printf("%s", rec);
		bytesRcvd = recv(d_sock, rec, 255, 0);
	}

	close(d_sock);
	return 0;
}

